package com.qf.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 用户退出的servlet
 */
@WebServlet("/logOut")
public class UserlogOutServlet extends HttpServlet {


    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        //获取session对象
        /**
         * getSession()----->getSession(boolean flag):如果当前存在session,这个参数就是false,表示获取
         * 如果当前不存在session,这个参数true,创建Session
         */
        HttpSession session = request.getSession();
        //手动删除session,让这个会话无效,取消任何数据绑定
        //public void invalidate()
        session.invalidate();

        //重写到index.jsp
        response.sendRedirect(request.getContextPath()+"/");

    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
